package Offer.offer2016;
import java.util.Stack;

public class Test07 
{	
	 static Stack<Integer> stack1 = new Stack<Integer>();
	 static Stack<Integer> stack2 = new Stack<Integer>();
	 public static void push(int node) 
	 {
	     stack1.push(node);  
	 }
	    
	 public static int pop() 
	 {
	    if(stack2.isEmpty())
	    {
	       while(!stack1.isEmpty())
	       {
	           int value=stack1.pop();
	           stack2.push(value);
	       }	        
	    }
	    if(stack2.isEmpty())
	    {
	    	throw new RuntimeException("����Ϊ��");
	    }
	    else
	    {
	    	return stack2.pop();
	    }
	 }
	public static void main(String[] args) 
	{
		push(1);
		push(2);
		push(3);
		push(4);
		pop();
		pop();
		pop();
		Queue queue = new Queue();
		queue.push(1);
		queue.push(2);
		queue.push(3);
		queue.push(4);
		System.out.print(queue.pop());
		System.out.print(queue.pop());
		queue.push(5);
		queue.push(6);
		System.out.print(queue.pop());
		System.out.print(queue.pop());
		System.out.print(queue.pop());
		System.out.print(queue.pop());
		
	}
}
class Queue{
	Stack<Integer> stack1 = new Stack<Integer>();
	Stack<Integer> stack2 = new Stack<Integer>();
	
	public void push(Integer item){
		stack1.push(item);
	}
	public Integer pop(){
		if(stack2.isEmpty()){
			while(!stack1.isEmpty()){
				stack2.push(stack1.pop());
			}
			if(!stack2.isEmpty()){
				return stack2.pop();
			}
		}else{
			return stack2.pop();
		}
		return null;
	}
}